{{csrf_field()}}
<div class="layui-form-item">
    <label for="" class="layui-form-label">昵称</label>
    <div class="layui-input-inline">
        <input type="text" name="name" value="{{ $user->name ?? old('name') }}" lay-verify="required" placeholder="请输入昵称" class="layui-input" >
    </div>
</div>

<div class="layui-form-item">
    <label for="" class="layui-form-label">手机号</label>
    <div class="layui-input-inline">
        <input type="text" name="phone" value="{{$user->phone??old('phone')}}" required="phone" lay-verify="phone" placeholder="请输入手机号" class="layui-input">
    </div>
</div>

<div class="layui-form-item">
    <label for="" class="layui-form-label">密码</label>
    <div class="layui-input-inline">
        <input type="password" name="password" placeholder="请输入密码" class="layui-input">
    </div>
</div>

<div class="layui-form-item">
    <label for="" class="layui-form-label">确认密码</label>
    <div class="layui-input-inline">
        <input type="password" name="password_confirmation" placeholder="请输入密码" class="layui-input">
    </div>
</div>

<div class="layui-form-item">
    <label for="" class="layui-form-label">头像</label>
    <div class="layui-input-block">
        <div class="layui-upload">
            <button type="button" class="layui-btn" id="uploadPic"><i class="layui-icon">&#xe67c;</i>图片上传</button>
            <div class="layui-upload-list" >
                <ul id="layui-upload-box" class="layui-clear">
                    @if(isset($user->avatar))
                        <li><img src="{{ $user->avatar }}" /><p>上传成功</p></li>
                    @endif
                </ul>
                <input type="hidden" name="avatar" id="avatar" value="{{ $user->avatar??'' }}">
            </div>
        </div>
    </div>
</div>

<div class="layui-form-item">
    <label for="" class="layui-form-label">省</label>
    <div class="layui-input-inline">
        <select name="province" lay-verify="required" onchange="selectCity(this,'city')">
            <option value="0">==请选择省==</option>
            @foreach($provinceData as $item)
                <option value="{{ $item->id }}">{{ $item->name }}</option>
            @endforeach
        </select>
    </div>
</div>

<div class="layui-form-item">
    <label for="" class="layui-form-label">市</label>
    <div class="layui-input-inline">
        <select name="city" id="city" onchange="selectCity(this,'region')">
            <option value="0">==市==</option>
        </select>
    </div>
</div>

<div class="layui-form-item">
    <label for="" class="layui-form-label">区/县</label>
    <div class="layui-input-inline">
        <select name="region" id="region">
            <option value="0">==区/县==</option>
        </select>
    </div>
</div>

<div class="layui-form-item layui-hide">
    <input type="button" lay-submit lay-filter="LAY-user-front-submit" id="LAY-user-front-submit" value="确认">
</div>

<script>
    // 下拉选择市和地区
    // obj 当前对象
    // selectName 给选中下个处理html的ID 字符串
    function selectCity(obj, selectName) {
        // 得到选中的值
        let value = $(obj).val();
        // 以省份ID得到市 发起ajax请求
        $.get('{{ route('admin.district.city') }}', {id: value}).then(jsonArr => {
            let html = '<option value="0">==市==</option>';
            // 循环 map  for  for in    for of    $.each
            jsonArr.map(item => {
                var {id, name} = item;
                html += `<option value="${id}">${name}</option>`;
            });
            $('#' + selectName).html(html);
        });
    }
</script>
